package com.hjs.servlet.dailyinspection.renovatedetail;

import com.hjs.bean.RenovateDetail;
import com.hjs.mapper.DailyInspectRecordingMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author violetfreesia
 * @date 2020/6/19
 **/
@Slf4j
@WebServlet("/renovateDetail/update")
public class UpdateRenovateDetail extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        RequestUtil requestUtil = new RequestUtil(request, response);
        Mapper<DailyInspectRecordingMapper> dailyInspectRecordingMapperMapper = new Mapper<>(DailyInspectRecordingMapper.class);
        try {
            RenovateDetail renovateDetail = new RenovateDetail(requestUtil.getInt("renovateDetailID"), requestUtil.getDate("renovateDate")
                    , requestUtil.getInt("technicianID"), requestUtil.getString("remarks"), null);
            DailyInspectRecordingMapper dailyInspectRecordingMapper = dailyInspectRecordingMapperMapper.getMapper();
            boolean result = dailyInspectRecordingMapper.updateOneRenovateDetail(renovateDetail);
            requestUtil.responseIsSuccess(result,"更新失败");
        } catch (Exception e) {
            log.error(e.toString());
            requestUtil.responseFail("未知错误");
        } finally {
            dailyInspectRecordingMapperMapper.closeSession();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request, response);
    }
}
